<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>版本和季度管理</title>
    <link rel="stylesheet" href="Public/Plug/layui/css/layui.css" media="all" />
</head>

<body>
<div class="admin-main">
    <div style="position: relative;" class="layui-row">
        <button type="button" class="layui-btn" id="add-version">添加版本</button>
        <button type="button" class="layui-btn" id="add-season">添加季度</button>
    </div>
    <div style="position: relative;" class="layui-row">
        <div style="margin: 10px 0px 0px 20px;" class="layui-row">
            <div class="layui-col-md8">
                <div style="font-size: 18px;font-weight: bold;">最新版本</div>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-md12">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th>版本号</th>
                        <th>当前版本</th>
                        <th>创建时间</th>
                        <th>更新时间</th>
                    </tr>
                    </thead>
                    <tbody>
                    {foreach $versionInfo as $val}
                    <tr>
                        <td>{$val.versionNumber}</td>
                        <td>{$val.isCurrent}</td>
                        <td>{$val.createTime}</td>
                        <td>{$val.updateTime}</td>

                    </tr>
                    {/foreach}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div style="position: relative;" class="layui-row">
        <div style="margin: 10px 0px 0px 20px;" class="layui-row">
            <div class="layui-col-md8">
                <div style="font-size: 18px;font-weight: bold;">最新季度</div>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-md12">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th>季度号</th>
                        <th>当前季度</th>
                        <th>创建时间</th>
                        <th>更新时间</th>
                    </tr>
                    </thead>
                    <tbody>
                    {foreach $seasonInfo as $val}
                    <tr>
                        <td>{$val.seasonNumber}</td>
                        <td>{$val.isCurrent}</td>
                        <td>{$val.createTime}</td>
                        <td>{$val.updateTime}</td>

                    </tr>
                    {/foreach}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="Public/Plug/layui/layui.js"></script>
    <script>
        layui.use(['layer','element','form'], function() {
            var	$ = layui.jquery,
                element = layui.element,
                form = layui.form;

            $("#add-version").on('click',function () {
                layer.prompt({ title: '请输入要命名的版本号，并确认',formType: 0}, function(versionNumber, index){

                    if(versionNumber == ""){
                        layer.msg("版本号不能为空", {
                            icon: 2,//失败的表情
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        });
                        return;
                    }
                    if(versionNumber.length>50){
                        layer.msg("版本号过长", {
                            icon: 2,//失败的表情
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        });
                        return;
                    }

                    var url = "{U('Main/addVersionOrSeason')}";
                    $.post(url,{ number:versionNumber,type:'version'},function(data){
                        if(data.status !="error"){
                            layer.msg(data.msg, {
                                icon: 1,//成功的表情
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                location.reload();
                            });
                            return;
                        }else{
                            layer.msg(data.msg, {
                                icon: 2,//失败的表情
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                //  location.reload();
                            });
                            return;
                        }
                    });
                });
            });
            $("#add-season").on('click',function () {
                layer.prompt({ title: '请输入要命名的季度号，并确认',formType: 0}, function(seasonNumber, index){

                    if(seasonNumber == ""){
                        layer.msg("季度不能为空", {
                            icon: 2,//失败的表情
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        });
                        return;
                    }
                    {literal}
                    var regu =/^[0-9]{4}.S[0-9]{1}$/;
                    {/literal}
                    if(!regu.test(seasonNumber)){
                        layer.msg("季度格式错误", {
                            icon: 2,//失败的表情
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        });
                        return;
                    }

                    var url = "{U('Main/addVersionOrSeason')}";
                    $.post(url,{ number:seasonNumber,type:'season'},function(data){
                        if(data.status !="error"){
                            layer.msg(data.msg, {
                                icon: 1,//成功的表情
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                location.reload();
                            });
                            return;
                        }else{
                            layer.msg(data.msg, {
                                icon: 2,//失败的表情
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                //  location.reload();
                            });
                            return;
                        }
                    });
                });
            });
        });
    </script>
</body>

</html>